import { receiveOrder, queryOrderInfoDetail } from '../../services/order'
// import { vehicleBehavior } from '../../behaviors/vehicle'
import { getAppointTimeInfo } from '../../utils/order'
import { queryPackageDetail } from '../../services/project'

Page({
  /**
   * 页面的初始数据
   */
  data: {
    orderId:"",
    inspectInfo:{},
    showDialogConfirm:false,
    dialogMsg:"",
    currentItem: {}
  },

  onLoad(options){
    if(!options){
      return
    }
    const id = options.id || ""
    if(id){
      this.setData({
        orderId:id
      })
      this.getOrderInfo(id)
    }
  },

  async getOrderInfo(orderId){
    let res = await queryOrderInfoDetail(orderId)
    console.log("res>>>", res)
    if(res.code === 200){
      let resData = res.data
      this.setData({
        inspectInfo: resData
      })
      this.getPackageInfoDetail(resData.appointPackageId)
      let appointTimeInfo = getAppointTimeInfo(resData.appointDate, resData.appointTime)
      this.setData({
        ['inspectInfo.appointTimeInfo']: appointTimeInfo
      })
    }
  },

  async getPackageInfoDetail(id){
    let res = await queryPackageDetail(id)
    if(res.code === 200){
      let packageInfo = res.data
      this.setData({
        ['inspectInfo.detectProjectName']: packageInfo.detectProjectName || ""
      })
    }
  },
  
  confirmInfo(){
    this.setData({
      showDialogConfirm: true,
      dialogMsg: "是否确认接单?",
    })
  },

  async handleConfirm(){
    let confirmRes = await receiveOrder(this.data.orderId)
    console.log("confirmRes>>>", confirmRes)
    if(confirmRes.code === 200){
      wx.reLaunch({
        url: `/pages/order-take-success/order-take-success?orderId=${this.data.orderId}`,
      })
    }
  }
})